package com.efrei.uchat.client.gui.view;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;


public class DefaultTab extends JPanel {

	private static final long serialVersionUID = 7220608856634938689L;
	
	private JButton btnAdd;
	private JList listCrooms;
	private JTextPane txtpnCrooms;
	private JButton btnRefresh;
	
	public DefaultTab() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, 1.0, 1.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		this.txtpnCrooms = new JTextPane();
		this.txtpnCrooms.setEditable(false);
		this.txtpnCrooms.setBackground(UIManager.getColor("SplitPane.background"));
		this.txtpnCrooms.setText("Crooms :");
		GridBagConstraints gbc_txtpnCrooms = new GridBagConstraints();
		gbc_txtpnCrooms.anchor = GridBagConstraints.CENTER;
		gbc_txtpnCrooms.insets = new Insets(0, 0, 5, 5);
		gbc_txtpnCrooms.gridx = 0;
		gbc_txtpnCrooms.gridy = 1;
		add(this.txtpnCrooms, gbc_txtpnCrooms);
		
		this.listCrooms = new JList();
		this.listCrooms.setToolTipText("");
		this.listCrooms.setMinimumSize(new Dimension(100, 300));
		GridBagConstraints gbc_list = new GridBagConstraints();
		gbc_list.gridwidth = 2;
		gbc_list.fill = GridBagConstraints.BOTH;
		gbc_list.insets = new Insets(0, 0, 5, 5);
		gbc_list.gridx = 1;
		gbc_list.gridy = 1;
		add(this.listCrooms, gbc_list);
		listCrooms.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		
		btnAdd = new JButton("add");
		GridBagConstraints gbc_btnAdd = new GridBagConstraints();
		gbc_btnAdd.insets = new Insets(0, 0, 0, 5);
		gbc_btnAdd.anchor = GridBagConstraints.CENTER;
		gbc_btnAdd.gridx = 1;
		gbc_btnAdd.gridy = 2;
		add(btnAdd, gbc_btnAdd);
		
		this.btnRefresh = new JButton("Refresh");
		GridBagConstraints gbc_btnRefresh = new GridBagConstraints();
		gbc_btnRefresh.insets = new Insets(0, 0, 0, 5);
		gbc_btnRefresh.gridx = 2;
		gbc_btnRefresh.gridy = 2;
		add(this.btnRefresh, gbc_btnRefresh);
	}

	public DefaultTab addController(ActionListener controller) {
		btnAdd.addActionListener(controller);
		return this;
	}
	
	public JList getListCrooms() {
		return listCrooms;
	}
	
	public JButton getBtnAdd() {
		return btnAdd;
	}
	
	public JButton getBtnRefresh() {
		return btnRefresh;
	}
}
